<template>
	<view class="container">
		<view v-if="TripList.length ==0">
			<view class="tabsContent">
				<u-empty mode="data" width="280" height="280" textSize="28"
					icon="http://cdn.uviewui.com/uview/empty/data.png" text="暂无任何行程"></u-empty>
			</view>
		</view>
		<view class="formBox" v-for="(item,index) in TripList" :key="index">
			<view class="trip-num">行程列表{{index+1}}</view>
			<view>
				<view class="line">
					<view class="line-title">用户姓名：</view>
					<u--text :size="26" color="#999999" :text="item.userName"></u--text>
				</view>
				<view class="line">
					<view class="line-title">居住地址：</view>
					<u--text :size="26" lineHeight="28" wordWrap="break-word" color="#999999" :text="item.address">
					</u--text>
				</view>
				<view class="line">
					<view class="line-title">行程信息：</view>
					<view style="font-size: 26rpx;color:#999999">{{item.startArea}}</view>
					--
					<view style="font-size: 26rpx;color:#999999">{{item.endArea}}</view>
				</view>
				<view class="line">
					<view class="line-title">交通工具：</view>
					<u--text :size="26" color="#999999" :text="item.tool"></u--text>
				</view>
				<view class="line">
					<view class="line-title">交通班次：</view>
					<u--text :size="26" color="#999999" :text="item.number"></u--text>
				</view>
				<view class="line">
					<view class="line-title">行程时间：</view>
					<view style="font-size: 26rpx;color:#999999">{{item.startTime}}</view>
					-
					<view style="font-size: 26rpx;color:#999999">{{item.endTime}}</view>
				</view>
			</view>
			<u-gap height="16"></u-gap>
			<view class="line line-btn">
				<u-button type="primary" style="width: 40%; height: 100%;" :plain="true" text="编辑" @click="edit(item)">
				</u-button>
				<u-button type="error" style="width: 40%; height: 100%;" :plain="true" text="删除"
					@click="delTrip(item,index)">
				</u-button>
			</view>
		</view>
		<view style="width:100% ;height:164rpx ;">
		</view>
		<view class="bottomBtn">
			<u-button type="primary" text="添加行程信息" @click="getxingcheng()"></u-button>
		</view>
		<u-modal :show="deleteShow" :title="deleteTitle" showCancelButton buttonReverse :zoom="false"
			:closeOnClickOverlay="true" @confirm="deleteConfirm" @cancel="deleteShow = false"
			@close="deleteShow = false "></u-modal>
	</view>
</template>

<script>
	import api from '@/api/api.js';
	export default {
		username: '',
		components: {},
		data() {
			return {
				pageNum: 1,
				pageSize: 10,
				TripList: [],
				num: null, //条数
				empty: false, //是否为空
				deleteShow: false,
				deleteTitle: '是否确认删除',
				deleteId: null,
			}
		},
		onLoad() {
			this.getTripListone()
		},
		onShow() {
			this.deleteShow = false
		},
		// 下拉刷新
		onPullDownRefresh() {
				const _that=this
				_that.pageNum=1
				this.myactivitylist=[]
				this.pageNum =1
				this.num=null
				setTimeout(function () {
					uni.stopPullDownRefresh();
					_that.getTripListone();
				}, 500);

		},
		methods: {
			// 获取行程列表
			getTripListone() {
				let userInfo = uni.getStorageSync('userInfo')
				api.getTrip({
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					userId: userInfo.id
				}).then(res => {
					console.log(res)
					this.TripList = res.data.rows
					this.num=Math.ceil(res.data.total/this.pageSize)//总条数除一页多少条向上取整
					this.pageNum++
				})
			},
			// 添加
			getxingcheng() {
				uni.$u.route({
					url: '/pages/trip/form',
				})
			},
			// 编辑
			edit(item) {
				uni.$u.route({
					type: "navigateTo",
					url: '/pages/trip/form',
					params: {
						id: item.id
					}
				})
			},
			//详情
			// watch(item) {
			// 	uni.$u.route({
			// 		url: '/pages/trip/details',
			// 		params: {
			// 			id: item.id
			// 		}
			// 	})
			// },
			// 删除访客信息
			delTrip(item, index) {
				this.deleteShow = true;
				this.deleteTitle = `是否确认删除 行程列表${index+1}`
				this.deleteId = item.id
			},
			// 删除
			deleteConfirm() {
				api.deletTrip(this.deleteId).then(res => {
					if (res.data.code == 200) {
						this.pageNum = 1
						this.TripList = []
						this.num = null
						this.getTripListone()
						setTimeout(() => {
							uni.$u.toast('删除成功')
							this.deleteShow = false;
						}, 300)
					}
				}).catch(err => {
					uni.$u.toast(err.msg)

				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tabsContent {
		margin-top: 16rpx;
		width: 100%;
		background-color: #FFFFFF;
		height: 600rpx;
	}

	.container {
		width: calc(100% - 32rpx);
		padding: 0 16rpx;
	}

	.trip-num {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.title-left {
		width: 60rpx;
	}

	.formBox {
		width: calc(100% - 64rpx);
		padding: 16rpx 32rpx;
		border-radius: 8rpx;
		background-color: #FFFFFF;
		margin: 16rpx 0;

		.line-btn {
			justify-content: space-around;
		}

		.line {
			display: flex;
			width: 100%;
			height: 60rpx;
			line-height: 60rpx;

			.line-title {
				width: 150rpx;
				font-size: 28rpx;

			}
		}
	}

	.bottomBtn {
		position: fixed;
		width: calc(100% - 63rpx);
		padding: 32rpx;
		bottom: 0;
		left: 0;
		background-color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
		box-shadow: 0rpx 1rpx 8rpx 0rpx #e5e5e5;
	}
</style>
